import request from "../../../utils/request"
import { ResponseCategoryData, AttrResponseData } from "./type"

enum API {
  //获取已有品牌接口
  FIRST_CATEGORY_URL = "/admin/product/getCategory1",
  SECCEND_CATEGORY_URL = "/admin/product/getCategory2/",
  THIRD_CATEGORY_URL = "/admin/product/getCategory3/",
  //获取分类下已有属性值
  ATTR_URL = "/admin/product/attrInfoList/",
  ADD_UPDATE_URL = "/admin/product/saveAttrInfo",
  DELETE_URL = "/admin/product/deleteAttr/",
}

export const reqForstCategory = () =>
  request.get<any, ResponseCategoryData>(API.FIRST_CATEGORY_URL)

export const reqSeccendCategory = (id: number | string) =>
  request.get<any, ResponseCategoryData>(API.SECCEND_CATEGORY_URL + `${id}`)

export const reqThirdCategory = (id: number | string) =>
  request.get<any, ResponseCategoryData>(API.THIRD_CATEGORY_URL + `${id}`)

export const reqAttr = (
  c1Id: number | string,
  c2Id: number | string,
  c3Id: number | string,
) =>
  request.get<any, AttrResponseData>(API.ATTR_URL + `${c1Id}/${c2Id}/${c3Id}`)

export const reqAddOrUpdateAttr = (data: Attr) =>
  request.post<any, any>(API.ADD_UPDATE_URL, data)

export const reqDeleteAttr = (id: number | string) =>
  request.delete<any, any>(API.DELETE_URL + `${id}`)
